home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / man / cat.1 / st.1 < prev    next >
Text File  |  1995-07-25  |  10KB  |  265 lines

  1.  
  2.  
  3.  
  4.      SSSSTTTT((((1111))))                    XXXXEEEENNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV                     SSSSTTTT((((1111))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.           st - Sound Tools - sound sample file and effects libraries.
  10.  
  11.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.           cccccccc _f_i_l_e._c ----oooo _f_i_l_e lllliiiibbbbsssstttt....aaaa
  13.  
  14.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  15.           _S_o_u_n_d _T_o_o_l_s is a library of sound sample file format
  16.           readers/writers and sound effects processors.
  17.  
  18.           Sound Tools includes skeleton C files to assist you in
  19.           writing new formats and effects. The full skeleton driver,
  20.           skel.c, helps you write drivers for a new format which has
  21.           data structures. The simple skeleton drivers help you write
  22.           a new driver for raw (headerless) formats, or for formats
  23.           which just have a simple header followed by raw data.
  24.  
  25.           Most sound sample formats are fairly simple: they are just a
  26.           string of bytes or words and are presumed to be sampled at a
  27.           known data rate.  Most of them have a short data structure
  28.           at the beginning of the file.
  29.  
  30.      IIIINNNNTTTTEEEERRRRNNNNAAAALLLLSSSS
  31.           The Sound Tools formats and effects operate on an internal
  32.           buffer format of signed 32-bit longs.  The data processing
  33.           routines are called with buffers of these samples, and
  34.           buffer sizes which refer to the number of samples processed,
  35.           not the number of bytes.  File readers translate the input
  36.           samples to signed longs and return the number of longs read.
  37.           For example, data in linear signed byte format is left-
  38.           shifted 24 bits.
  39.  
  40.           This does cause problems in processing the data. For
  41.           example:
  42.                *obuf++ = (*ibuf++ * *ibuf++)/2;
  43.           would _n_o_t mix down left and right channels into one
  44.           monophonic channel, because the resulting samples would
  45.           overflow 32 bits.  Instead, the ``avg'' effects must use:
  46.                *obuf++ = *ibuf++/2 * *ibuf++/2;
  47.  
  48.           Stereo data is stored with the left and right speaker data
  49.           in successive samples.  Quadraphonic data is stored in this
  50.           order: left front, right front, left rear, right rear.
  51.  
  52.      FFFFOOOORRRRMMMMAAAATTTTSSSS
  53.           A _f_o_r_m_a_t is responsible for translating between sound sample
  54.           files and an internal buffer.  The internal buffer is store
  55.           in signed longs with a fixed sampling rate.  The _f_o_r_m_a_t
  56.           operates from two data structures: a format structure, and a
  57.           private structure.
  58.  
  59.           The format structure contains a list of control parameters
  60.  
  61.  
  62.  
  63.      Page 1                                          (printed 7/27/94)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      SSSSTTTT((((1111))))                    XXXXEEEENNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV                     SSSSTTTT((((1111))))
  71.  
  72.  
  73.  
  74.           for the sample: sampling rate, data size (bytes, words,
  75.           floats, etc.), style (unsigned, signed, logarithmic), number
  76.           of sound channels.  It also contains other state
  77.           information: whether the sample file needs to be byte-
  78.           swapped, whether fseek() will work, its suffix, its file
  79.           stream pointer, its _f_o_r_m_a_t pointer, and the _p_r_i_v_a_t_e
  80.           structure for the _f_o_r_m_a_t .
  81.  
  82.           The _p_r_i_v_a_t_e area is just a preallocated data array for the
  83.           _f_o_r_m_a_t to use however it wishes. It should have a defined
  84.           data structure and cast the array to that structure. See
  85.           voc.c for the use of a private data area. Voc.c has to track
  86.           the number of samples it writes and when finishing, seek
  87.           back to the beginning of the file and write it out.  The
  88.           private area is not very large.  The ``echo'' effect has to
  89.           malloc() a much larger area for its delay line buffers.
  90.  
  91.           A _f_o_r_m_a_t has 6 routines:
  92.  
  93.           startread           Set up the format parameters, or read in
  94.                               a data header, or do what needs to be
  95.                               done.
  96.  
  97.           read                Given a buffer and a length: read up to
  98.                               that many samples, transform them into
  99.                               signed long integers, and copy them into
  100.                               the buffer.  Return the number of
  101.                               samples actually read.
  102.  
  103.           stopread            Do what needs to be done.
  104.  
  105.           startwrite          Set up the format parameters, or write
  106.                               out a data header, or do what needs to
  107.                               be done.
  108.  
  109.           write               Given a buffer and a length: copy that
  110.                               many samples out of the buffer, convert
  111.                               them from signed longs to the
  112.                               appropriate data, and write them to the
  113.                               file.  If it can't write out all the
  114.                               samples, fail.
  115.  
  116.           stopwrite           Fix up any file header, or do what needs
  117.                               to be done.
  118.  
  119.      EEEEFFFFFFFFEEEECCCCTTTTSSSS
  120.           An effects loop has one input and one output stream.  It has
  121.           5 routines.
  122.  
  123.           getopts             is called with a character string
  124.                               argument list for the effect.
  125.  
  126.  
  127.  
  128.  
  129.      Page 2                                          (printed 7/27/94)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      SSSSTTTT((((1111))))                    XXXXEEEENNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV                     SSSSTTTT((((1111))))
  137.  
  138.  
  139.  
  140.           start               is called with the signal parameters for
  141.                               the input and output streams.
  142.  
  143.           flow                is called with input and output data
  144.                               buffers, and (by reference) the input
  145.                               and output data sizes.  It processes the
  146.                               input buffer into the output buffer, and
  147.                               sets the size variables to the numbers
  148.                               of samples actually processed.  It is
  149.                               under no obligation to fill the output
  150.                               buffer.
  151.  
  152.           drain               is called after there are no more input
  153.                               data samples.  If the effect wishes to
  154.                               generate more data samples it copies the
  155.                               generated data into a given buffer and
  156.                               returns the number of samples generated.
  157.                               If it fills the buffer, it will be
  158.                               called again, etc.  The echo effect uses
  159.                               this to fade away.
  160.  
  161.           stop                is called when there are no more input
  162.                               samples to process.  _s_t_o_p may generate
  163.                               output samples on its own.  See echo.c
  164.                               for how to do this, and see that what it
  165.                               does is absolutely bogus.
  166.  
  167.      CCCCOOOOMMMMMMMMEEEENNNNTTTTSSSS
  168.           Theoretically, formats can be used to manipulate several
  169.           files inside one program.  Multi-sample files, for example
  170.           the download for a sampling keyboard, can be handled cleanly
  171.           with this feature.
  172.  
  173.      PPPPOOOORRRRTTTTAAAABBBBIIIILLLLIIIITTTTYYYY PPPPRRRROOOOBBBBLLLLEEEEMMMMSSSS
  174.           Many computers don't supply arithmetic shifting, so do
  175.           multiplies and divides instead of << and >>.  The compiler
  176.           will do the right thing if the CPU supplies arithmetic
  177.           shifting.
  178.  
  179.           Do all arithmetic conversions one stage at a time.  I've had
  180.           too many problems with "obviously clean" combinations.
  181.  
  182.           In general, don't worry about "efficiency". The sox.c base
  183.           translator is disk-bound on any machine (other than a 8088
  184.           PC with an SMD disk controller). Just comment your code and
  185.           make sure it's clean and simple.  You'll find that DSP code
  186.           is extremely painful to write as it is.
  187.  
  188.      BBBBUUUUGGGGSSSS
  189.           The HCOM format is not re-entrant; it can only be used once
  190.           in a program.
  191.  
  192.  
  193.  
  194.  
  195.      Page 3                                          (printed 7/27/94)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      SSSSTTTT((((1111))))                    XXXXEEEENNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV                     SSSSTTTT((((1111))))
  203.  
  204.  
  205.  
  206.           The program/library interface is pretty weak.  There's too
  207.           much ad-hoc information which a program is supposed to
  208.           gather up.  Sound Tools wants to be an object-oriented
  209.           dataflow architecture.
  210.  
  211.           The human ear can't really hear better than 20 bits.  With
  212.           an internal format of 16 bits, we will eventually destroy
  213.           information when used to mix CD's.  The internal format
  214.           should be 24-bit signed data.  But, with 24 bits you still
  215.           have to be careful multiplying.  Check the ``vibro'' effect
  216.           for how it handles this problem.
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.      Page 4                                          (printed 7/27/94)
  262.  
  263.  
  264.  
  265.